/**
 * Created by ROCK on 2017/11/28.
 */
(function () {
    'use strict';

    angular
        .module('gameplay.details.controller', [])
        .controller('GameplayDetailsController', GameplayDetailsController);

    GameplayDetailsController.$inject = ['$scope','$yikeUtils','$state','$ionicHistory','$ionicTabsDelegate','$timeout','localStorageService','$ionicLoading','$ionicScrollDelegate','$ionicPopup','$ionicModal','$rootScope'];
    /* @ngInject */
    function GameplayDetailsController($scope,$yikeUtils,$state,$ionicHistory,$ionicTabsDelegate,$timeout,localStorageService,$ionicLoading,$ionicScrollDelegate,$ionicPopup,$ionicModal,$rootScope){

        $scope.user=localStorageService.get('user');
        $scope.id = $state.params.id;
        $scope.type = $state.params.type;
        $scope.name = $state.params.name;
        console.log($scope.name);

        init();

        function init(){
            if($scope.type==1){
                pkScheme();
            }else if($scope.type==2) {
                openPlansDetail();
            }

        }


        //获取所有玩法
        //$scope.itemsList=[];
        //console.log($scope.itemsList);
        function pkScheme() {
            yikeTaishan.pkScheme($scope.user.token)
                .then(function (data) {
                    //console.log(data);
                    if(data.status == 1){
                        //for(var key in data.result.plan){
                        //    data.result.plan[key].state = false;
                        //    data.result.plan[key].playsState = false;
                        //    data.result.plan[key].collected = false;
                        //    data.result.plan[key].id_img = data.result.plan[key].id-1;
                        //    $scope.itemsList.push(data.result.plan[key].row);
                        //}
                        $scope.allplans = data.result.plan;
                        //console.log($scope.allplans);

                        for(var k in $scope.allplans){
                            if($scope.id == $scope.allplans[k].id){
                                $scope.row = $scope.allplans[k].row;
                                console.log($scope.row);
                            }
                        }
                    }
                    $scope.$digest();
                    $ionicLoading.hide();
                })
        }


        function openPlansDetail(){
            $ionicLoading.show({
                template: '<ion-spinner icon="bubbles"></ion-spinner>'
            });
            yikeTaishan.detailsList($scope.user.id,$scope.id)
                .then(function(data){
                    $ionicLoading.hide();
                    $scope.detailsMessage = data.result.collection.plans;
                    console.log($scope.detailsMessage);

                    /*$scope.openDetailsPlans();*/
                    $scope.$digest();
                });
        }



    }
})();
